<?php
namespace app\admin\controller;

use app\admin\code\BaseCode;
use app\admin\model\DesignCommentModel;
use app\admin\model\DesignLikeModel;
use app\admin\model\InstallCommentModel;
use app\admin\model\InstallLikeModel;
use app\admin\util\Page;
use app\admin\util\Response;
use think\Request;

class Install extends BaseMessage
{
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->_comment_model = new InstallCommentModel();
        $this->_like_model = new InstallLikeModel();
    }

    public function index(){
        if($this->request->isAjax()){
            $list = $this->_model->order('id desc')->select();
            foreach ($list as &$value){
                $imgs = $value->imgs;
                $imgs_list = [];
                foreach ($imgs as $img_value){
                    $imgs_list[] = $img_value['path'];
                }
                $value['imgs'] = $imgs_list;
                $value['user'] = $value['uid'];
                $value['comment_num'] = $this->_get_comment_num($value['id']);
                $value['like_num'] = $this->_get_like_num($value['id']);
            }
            $size = input('limit',$this->_size,'intval');
            $page = input('page',1,'intval');
            Response::json(BaseCode::SUCCESS,'',Page::return_page_data($list,$size,$page));
        }else{
            return view($this->_template_index);
        }
    }
}